<?php
/**
 * Created by PhpStorm.
 * User: kx520
 * Date: 2020-07-06
 * Time: 18:44
 */

namespace app\api\validate;


use app\lib\exception\ParameterException;
use think\Request;
use think\Validate;

class BaseValidate extends Validate
{
    public function goCheck(){
        // 1.获取参数
        //2.参数校验
        $request=Request::instance();
        $params=$request->param();
        $result = $this->batch()->check($params);
        if(!$result){
            $e=new ParameterException([
                'msg'=>$this->error,
            ]);
           // $e->msg=$this->error;
            throw $e;
        }else{
            return true;
        }
    }
    protected function isPositiveInteger($value,$rule='',$data='',$field=''){
        if(preg_match("/^[1-9][0-9]*$/",$value)){
            return true;
        }else{
            return false;
            // return $field.'必须是证整数';
        }

    }
    protected function isNotEmpty($value,$rule='',$data='',$field=''){
        if(empty($value)){
            return false;
        }else{
            return true;
        }
    }

}